package cn.stylefeng.guns.modular.school.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.school.entity.ClassSchoolTable;
import cn.stylefeng.guns.modular.school.entity.TeacherInfo;
import cn.stylefeng.guns.modular.school.model.params.ClassSchoolTableParam;
import cn.stylefeng.guns.modular.school.service.ClassSchoolTableService;
import cn.stylefeng.guns.modular.school.service.TeacherInfoService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 班级课表控制器
 *
 * @author
 * @Date 2020-05-02 18:36:29
 */
@Controller
@RequestMapping("/classSchoolTable")
public class ClassSchoolTableController extends BaseController {

    private String PREFIX = "/school/classSchoolTable";

    @Autowired
    private ClassSchoolTableService classSchoolTableService;
    @Autowired
    private TeacherInfoService teacherInfoService;

    /**
     * 跳转到主页面
     *
     * @author
     * @Date 2020-05-02
     */
    @RequestMapping("")
    public String index(Integer classId, String lessonId, String teacherCode) {
        setAttr("classId", classId);
        setAttr("lessonId", lessonId);
        setAttr("teacherCode", teacherCode);
        return PREFIX + "/classSchoolTable.html";
    }

    /**
     * 新增页面
     *
     * @author
     * @Date 2020-05-02
     */
    @RequestMapping("/add")
    public String add(Integer classId, String lessonId, String teacherCode) {
        setAttr("classId", classId);
        setAttr("lessonId", lessonId);
        TeacherInfo teacherInfo = teacherInfoService.getOne(new QueryWrapper<TeacherInfo>().eq("code", teacherCode));
        setAttr("teacherId", teacherInfo.getId());
        return PREFIX + "/classSchoolTable_add.html";
    }

    /**
     * 编辑页面
     *
     * @author
     * @Date 2020-05-02
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/classSchoolTable_edit.html";
    }

    /**
     * 新增接口
     *
     * @author
     * @Date 2020-05-02
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(ClassSchoolTableParam classSchoolTableParam) {
        this.classSchoolTableService.add(classSchoolTableParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author
     * @Date 2020-05-02
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(ClassSchoolTableParam classSchoolTableParam) {
        this.classSchoolTableService.update(classSchoolTableParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author
     * @Date 2020-05-02
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(ClassSchoolTableParam classSchoolTableParam) {
        this.classSchoolTableService.delete(classSchoolTableParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author
     * @Date 2020-05-02
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(ClassSchoolTableParam classSchoolTableParam) {
        ClassSchoolTable detail = this.classSchoolTableService.getById(classSchoolTableParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author
     * @Date 2020-05-02
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(ClassSchoolTableParam classSchoolTableParam,String teacherCode) {
        TeacherInfo teacherInfo = teacherInfoService.getOne(new QueryWrapper<TeacherInfo>().eq("code", teacherCode));
        classSchoolTableParam.setTeacherId(teacherInfo.getId());
        return this.classSchoolTableService.findPageBySpec(classSchoolTableParam);
    }

}


